// pages/recruit/recruit.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
      searchingContent:'',
      list:[],
      array: ['院系', '项目名称', '项目标签', '项目负责人'],
      searchcap:"",
      searchname:"",
      searchdepart:"",
      searchtag:"",
      index:0,
      status:1,
      idOfPrg:1,
      totalPages: 1,
      switch:0,
    },

    Parameters1: {
        orderBy: "create_time desc",
        pageNum: 1,
        pageSize: 10
      },
      Parameters2: {
        orderBy: "id asc",
        pageNum: 1,
        pageSize: 10
      },
    bindPickerChange: function(e) {
      console.log('picker发送选择改变，携带值为', e.detail.value)
      this.setData({
        index: e.detail.value
      })
    },

    gotoCreation(e) {
        wx.navigateTo({
          url: '/pages/recruit/team-creation/creation',
        })  
      }, 

      search:function(e){

           var val = e.detail.value;
           this.setData({
              searchingContent:val
           })
      },

      searching:function(e){
        this.setData({
          searchcap:"",
          searchname:"",
          searchdepart:"",
          searchtag:"",
          index:this.data.index,
          totalPages:1,
          list:[],
          switch:1,
        })
        this.Parameters2.pageNum=1;
        if (this.data.index==0)
        {
          this.setData({
            searchdepart:this.data.searchingContent,
            searchcap:"",
            searchname:"",
            searchtag:"",
          })
        }
        if(this.data.index==1)
        {
         this.setData({
           searchname:this.data.searchingContent,
           searchcap:"",
           searchdepart:"",
           searchtag:"",
         })
        }
        if(this.data.index==2)
        {
         this.setData({
           searchtag:this.data.searchingContent,
           searchcap:"",
           searchname:"",
           searchdepart:"",
         })
        }
        if(this.data.index==3)
        {
         this.setData({
           searchcap:this.data.searchingContent,
           searchname:"",
           searchdepart:"",
           searchtag:"",
         })
         console.log(this.data.searchcap)
       }
        wx.request({
          url: 'https://www.hschuangsai.com/search/condition',
          data: {
            captain: this.data.searchcap,
            department: this.data.searchdepart,
            name: this.data.searchname,
            pageParam:  
            {
              orderBy: "id asc",
              pageNum: 1,
              pageSize: 10
            },
            tag: this.data.searchtag,
            type: "3"
          },
          method: "POST",
          success: (result) => {
            if (result.statusCode!=200) {
              wx.showToast({
                  title: '搜索失败，请重试',
                  icon: 'none',
                  duration: 800     
                })  
          }
              console.log(result)
              this.setData({
                list: result.data.data.list,
                totalPages:result.data.data.pages
              })
          }
        })
      },
 /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      this.setData({
        searchingContent:this.data.searchingContent,
        searchcap:this.data.searchcap,
        searchname:this.data.searchname,
        searchdepart:this.data.searchdepart,
        searchtag:this.data.searchtag,
        totalPages: 1,
        switch:0,
    })
    this.setData({
      userInfo: wx.getStorageSync('userInfo'), // 用户的微信头像、昵称等信息
      loginFlag: wx.getStorageSync('loginFlag'), // 判断是否登录，登录为1，未登录为0或空
      sessionID: wx.getStorageSync('sessionID'),
      chuangNum: wx.getStorageSync('chuangNum')
    })
    wx.request({
      url: 'https://www.hschuangsai.com/search/condition',
      data: {
        captain: this.data.serachcap,
        department: this.data.searchdepart,
        name: this.data.searchname,
        pageParam: this.Parameters1,
        tag: this.data.searchtag,
        type: "3"
      },
      method: "POST",
      success: (result) => {
        if (result.statusCode!=200) {
          wx.showToast({
              title: '获取用户信息失败，请重试',
              icon: 'none',
              duration: 800     
            })  
      }
         console.log(result)
          this.setData({
            list: result.data.data.list,
            totalPages:result.data.data.pages
          })
          console.log(this.data.totalPages)
      }
    })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
     
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      this.setData({
        searchingContent:this.data.searchingContent,
        searchcap:this.data.searchcap,
        searchname:this.data.searchname,
        searchdepart:this.data.searchdepart,
        searchtag:this.data.searchtag,
        totalPages: 1,
        switch:0,
    })
    this.Parameters1.pageNum=1;
    wx.request({
      url: 'https://www.hschuangsai.com/search/condition',
      data: {
        captain: this.data.serachcap,
        department: this.data.searchdepart,
        name: this.data.searchname,
        pageParam: this.Parameters1,
        tag: this.data.searchtag,
        type: "3"
      },
      method: "POST",
      success: (result) => {
        if (result.statusCode!=200) {
          wx.showToast({
              title: '获取用户信息失败，请重试',
              icon: 'none',
              duration: 800     
            })  
      }
         console.log(result)
          this.setData({
            list: result.data.data.list,
            totalPages:result.data.data.pages
          })
          console.log(this.data.totalPages)
      }
    })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
      if (this.data.switch==0)
      {
        this.Parameters1.pageNum+=1;
        if(this.Parameters1.pageNum>=this.totalPages){
          console.log("加载失败")
        }else{
          wx.request({
            url: 'https://www.hschuangsai.com/search/condition',
            data: {
              captain: this.data.serachcap,
              department: this.data.searchdepart,
              name: this.data.searchname,
              pageParam: this.Parameters1,
              tag: this.data.searchtag,
              type: "3"
            },
            method: "POST",
            success: (result) => {
              if (result.statusCode!=200) {
                wx.showToast({
                    title: '获取项目列表，请重试',
                    icon: 'none',
                    duration: 800     
                  })  
            }
               console.log(result)
                this.setData({
                  list:[...this.data.list,...result.data.data.list],
                })
            }
          })
        }
      }
      else{
        this.Parameters2.pageNum+=1;
        if(this.Parameters2.pageNum>=this.totalPages){
          console.log("加载失败")
        }else{
          wx.request({
            url: 'https://www.hschuangsai.com/search/condition',
            data: {
              captain: this.data.serachcap,
              department: this.data.searchdepart,
              name: this.data.searchname,
              pageParam: this.Parameters2,
              tag: this.data.searchtag,
              type: "3"
            },
            method: "POST",
            success: (result) => {
              if (result.statusCode!=200) {
                wx.showToast({
                    title: '获取用户信息失败，请重试',
                    icon: 'none',
                    duration: 800     
                  })  
            }
               console.log(result)
                this.setData({
                  list:[...this.data.list,...result.data.data.list],
                })
            }
          })
        }
      }
      
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})